package ftest.movie.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class DescriptionMoviePage extends AnyPage {
	
	public DescriptionMoviePage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(id = "imdbsearch")
    public WebElement inputId;
	
	@FindBy(className = "digits")
	public WebElement inputImdb;
	
	@FindBy(name = "name")
	public WebElement inputTitle;
	
	@FindBy(name = "aka")
	public WebElement inputSecondName;
	
	@FindBy(name = "year")
	public WebElement inputYear;
	
	@FindBy(name = "duration")
	public WebElement inputDuration;
	
	@FindBy(name = "rating")
	public WebElement inputRating;
	
	@FindBy(id = "formats")
	public WebElement inputFormat;
	
	@FindBy(id = "own_yes")
	public WebElement checkOwnYes;
	
	@FindBy(id = "own_no")
	public WebElement checkOwnNo;
	
	@FindBy(id = "seen_yes")
	public WebElement checkHaveSeenYes;
	
	@FindBy(id = "seen_no")
	public WebElement checkHaveSeenNo;
	
	@FindBy(id = "loaned_yes")
	public WebElement checkLoanedYes;
	
	@FindBy(id = "loaned_no")
	public WebElement checkLoanedNo;
	
	@FindBy(name = "trailer")
	public WebElement inputTrailer;
	
	@FindBy(name = "notes")
	public WebElement inputNotes;
	
	@FindBy(id = "submit")
	public WebElement saveButton;
	
	@FindBy(name = "name")
	public WebElement validationTitleMsg;
	
	@FindBy(name = "year")
	public WebElement validationYearMsg;
	
	@FindBy(name = "format")
	public WebElement validationFormatMsg;
	
	public void selectOwn(boolean own) {
		if(own){
			selectOwnYes();
		}
		else{
			selectOwnNo();
		}		
	}

	public void selectHaveSeen(boolean haveSeen) {
		if(haveSeen){
			selectHaveSeenYes();
		}
		else{
			selectHaveSeenNo();
		}		
	}
	
	public void selectLoanedOut(boolean loanedOut) {
		if(loanedOut){
			selectLoanedOutYes();
		}			
		else{
			selectLoanedOutNo();
		}
	}
	
	private void selectLoanedOutNo() {
		if(checkLoanedNo.isSelected()){
			return;
		}
		checkLoanedNo.click();
		
	}

	private void selectLoanedOutYes() {
		if(checkLoanedYes.isSelected()){
			return;
		}
		checkLoanedYes.click();
		
	}

	private void selectHaveSeenNo() {
		if(checkHaveSeenNo.isSelected()){
			return;
		}
		checkHaveSeenNo.click();		
	}

	private void selectHaveSeenYes() {
		if(checkHaveSeenYes.isSelected()){
			return;
		}
		checkHaveSeenYes.click();		
	}

	private void selectOwnNo() {
		if(checkOwnNo.isSelected()){
			return;
		}
		checkOwnNo.click();
	}

	private void selectOwnYes() {
		if(checkOwnYes.isSelected()){
			return;
		}
		checkOwnYes.click();
	}	
}
